var t = require("../../@babel/runtime/helpers/interopRequireDefault");

require("../../@babel/runtime/helpers/Arrayincludes");

var o = t(require("../../utils/util.js")), a = getApp();

Page({
    data: {
        prop_goods_info: {},
        producer_id: "",
        goods_type: "",
        goods_id: "",
        mark: "",
        hoet: !1,
        enterAt: "",
        title: "",
        mark_id: "",
        fight_groups: "",
        loginshow: !1,
        groups_title: "",
        liveshow: !1,
        iPnoneBottomBol: !1,
        activity_id: "",
        is_open: "",
        store_id: 0,
        fromStock: "",
        is_toker: !1,
        mode: null,
        category_option_id: "",
        debtId: "",
        cid: 0,
        machineId: "",
        shareInfo: {}
    },
    onLoad: function(t) {
        console.log(t, "custom_params"), t.mid && a._setMid(t.mid), t.custom_params && a._setMid(JSON.parse(decodeURIComponent(t.custom_params)).mid), 
        wx.showLoading({
            title: "加载中..."
        }), this._datainit(), this.getiPnoneBottom(), t.liveshow && this.setData({
            liveshow: !0
        }), t.fromStock && this.setData({
            fromStock: t.fromStock
        });
        var o = null, e = new Map([ [ "group", "group_goods" ], [ "group_buy", "groupBuy" ], [ "69", "grabGroup" ], [ "99", "groupwork" ], [ "ywmGroup", "ywmGroup" ] ]);
        if (t.scene) {
            var i = decodeURIComponent(t.scene);
            if (i) {
                var s = [];
                s = i.split(",");
                for (var d = 0; d < s.length; d++) {
                    var r = [];
                    if ("id" == (r = s[d].split("="))[0]) o = r[1].split("/"), this.setData({
                        goods_id: o[0]
                    }); else if ("mid" == r[0]) a._setMid(r[1]); else if ("shop_id" == r[0]) a._setshopid(Number(r[1])); else if ("name" == r[0]) {
                        var n = e.has(r[1]) ? e.get(r[1]) : r[1];
                        o && o[1] && "group_goods" == n && this.setData({
                            store_id: o[1]
                        }), this.setData({
                            goods_type: n
                        }), wx.hideLoading();
                    } else "activity_id" == r[0] ? this.setData({
                        activity_id: r[1]
                    }) : "md" == r[0] ? (this.setData({
                        mode: r[1]
                    }), this.getRetailGoods()) : this._getData();
                }
            }
        } else if (t.shop_id && a._setshopid(Number(t.shop_id)), t.coid && this.setData({
            category_option_id: t.coid
        }), t.id && (o = t.id.split("/"), this.setData({
            goods_id: o[0]
        })), t.producer_id && this.setData({
            producer_id: t.producer_id
        }), t.mid && a._setMid(t.mid), t.mark && this.setData({
            mark: t.mark
        }), t.mark_id && this.setData({
            mark_id: t.mark_id
        }), t.start && this.setData({
            "enterAt.start": t.start
        }), t.end && this.setData({
            "enterAt.end": t.end
        }), t.fight_groups && this.setData({
            fight_groups: t.fight_groups
        }), t.vid && a._setvid(t.vid), t.circle_invitation_id && a._setcircleInvitationId(t.circle_invitation_id), 
        t.roomid && a._setroomid(t.roomid), t.activity_id && this.setData({
            activity_id: t.activity_id
        }), t.cid && this.setData({
            cid: t.cid
        }), t.machineId && this.setData({
            machineId: t.machineId,
            mark: "vending_machine",
            mark_id: t.machineId
        }), t.debtId && this.setData({
            debtId: t.debtId
        }), t.name) {
            var h = e.has(t.name) ? e.get(t.name) : t.name;
            wx.hideLoading(), o && o[1] && "group" == t.name && this.setData({
                store_id: o[1]
            }), t.md ? (this.setData({
                mode: t.md
            }), wx.hideLoading(), this.getRetailGoods()) : this.setData({
                goods_type: h
            });
        }
        wx.hideLoading(), this.data.goods_type || "retailGood" == t.name || this._getData(), 
        "kind" in t == 1 && this.setData({
            vieText: t.kind
        });
    },
    getiPnoneBottom: function() {
        try {
            wx.getStorageSync("iPhoneBottom") && this.setData({
                iPnoneBottomBol: !0
            });
        } catch (t) {}
    },
    onParentEvent: function(t) {
        this.setData({
            title: t.detail[0]
        });
    },
    touchStart: function(t) {
        var o = t.touches[0].pageY;
        this.setData({
            sy: o
        });
    },
    touchMove: function(t) {
        this.setData({
            endy: t.touches[0].pageY
        });
    },
    touchEnd: function() {
        this.data.sy - this.data.endy > 100 && this.data.showIn && this.setData({
            boxHeight: "",
            xqBoxShow: !0,
            showIn: !1
        });
    },
    onReady: function() {},
    onShow: function(t) {
        wx.showShareMenu({
            withShareTicket: !1,
            menus: [ "shareAppMessage", "shareTimeline" ]
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function(t) {
        try {
            "goods" == this.data.goods_type ? this.cGoods.reachBottom() : "supplierGoods" == this.data.goods_type ? this.supplierGoods.reachBottom() : "hotelGoods" == this.data.goods_type && this.hotelGoods.reachBottom();
        } catch (t) {}
        this.setData({
            showIn: !0
        });
    },
    onShareTimeline: function() {
        var t = wx.getStorageSync("yz_uid"), o = wx.getStorageSync("setShopId"), a = wx.getStorageSync("GoddsShareImg"), e = "";
        if (t && (e = t), "group_goods" == this.data.goods_type) {
            var i = this.data.store_id && 0 != this.data.store_id ? "id=".concat(this.data.goods_id, "/").concat(this.data.store_id, "&mid=").concat(e, "&name=group") : "id=".concat(this.data.goods_id, "&mid=").concat(e, "&name=group");
            return {
                title: this.data.title,
                query: i,
                imageUrl: a || ""
            };
        }
        return "zhpGroup" == this.data.goods_type || "ywmGroup" == this.data.goods_type ? {
            title: this.data.title ? this.data.title : "",
            query: "id=" + this.data.goods_id + "&mid=" + e + "&name=" + this.data.goods_type,
            imageUrl: a || ""
        } : "groupBuy" == this.data.goods_type || "grabGroup" == this.data.goods_type ? {
            title: this.data.title ? this.data.title : "",
            path: "id=" + this.data.goods_id + "&mid=" + e + "&name=" + this.data.goods_type
        } : {
            title: this.data.shareInfo.title || this.data.title,
            query: "id=".concat(this.data.goods_id, "&mid=").concat(e, "&shop_id=").concat(o),
            imageUrl: this.data.shareInfo.imgUrl || ""
        };
    },
    onShareAppMessage: function(t) {
        var o = wx.getStorageSync("yz_uid"), a = "";
        o && (a = o);
        var e = wx.getStorageSync("setShopId"), i = wx.getStorageSync("GoddsShareImg");
        console.log(this.data.shareInfo.title, this.data.title);
        var s = {
            title: this.data.shareInfo.title || this.data.title || "",
            path: "/packageA/detail_v2/detail_v2?id=" + this.data.goods_id + "&mid=" + a,
            imageUrl: this.data.shareInfo.imgUrl || i || ""
        };
        if (e && (s.path = s.path + "&shop_id=" + e), "zhpGroup" != this.data.goods_type && "ywmGroup" != this.data.goods_type || (s.path = s.path + "&name=" + this.data.goods_type), 
        "group_goods" == this.data.goods_type) {
            var d = null;
            this.data.store_id && 0 != this.data.store_id && "undefined" != this.data.store_id && (d = "/" + this.data.store_id), 
            0 != this.data.goods_id ? s.path = "/packageA/detail_v2/detail_v2?id=" + this.data.goods_id + "&mid=" + a + "&name=group" : s.path = "/packageA/detail_v2/detail_v2?id=0" + d + "fight_groups=" + this.data.fight_groups + "&mid=" + a + "&name=group";
        }
        if ([ "groupBuy", "grabGroup", "retailGood", "starGroup", "zhpGroup" ].includes(this.data.goods_type) && (s.path = "/packageA/detail_v2/detail_v2?id=" + this.data.goods_id + "&mid=" + a + "&name=" + this.data.goods_type), 
        "starGroup" == this.data.goods_type) {
            var r = {};
            if (r.path = s.path, "button" == t.from) {
                r.title = t.target.dataset.name, r.thumb = t.target.dataset.thumb;
                var n = t.target.dataset.id, h = t.target.dataset.type;
                h && "startGroupDetail" == h && (r.path = "/packageH/starMusic/starMusicGroupDetails/starMusicGroupDetails?mid=" + a + "&id=" + n);
            }
            return r;
        }
        return "retailGood" == this.data.goods_type && (s.path = s.path + "&md=" + this.options.md), 
        {
            title: s.title,
            path: s.path,
            imageUrl: s.imageUrl
        };
    },
    onPageScroll: o.default.throttle(function(t) {
        var o = t[0].scrollTop;
        o > 35 ? this.data.hoet || this.setData({
            hoet: !0
        }) : this.data.hoet && this.setData({
            hoet: !1
        }), this.setData({
            datop: o
        });
    }, 100),
    _datainit: function() {
        this.setData({
            goods_type: "",
            goods_id: "",
            goods_info: {},
            goods_info_str: "",
            mark: "",
            loginshow: !1
        });
    },
    _getData: function() {
        var t = this, o = a.getNetAddresss("goods.goods.get-goods-page"), e = {
            id: Number(this.data.goods_id),
            mark: this.data.mark,
            mark_id: this.data.mark_id,
            url: ""
        };
        this.data.category_option_id && (e.category_option_id = this.data.category_option_id), 
        this.data.machineId && (e.automat_machine_id = this.data.machineId), a._postNetWork({
            showToastIn: !1,
            url: o,
            data: e,
            success: function(o) {
                var a = o.data;
                if (1 == a.result) {
                    var e, i, s, d = a.data, r = null === (e = d.plugin) || void 0 === e ? void 0 : e.coupon_store_goods;
                    if ("cps_brand" == a.data.goods_type) {
                        var n = a.data.plugin.aggregation_cps_brand_goods && a.data.plugin.aggregation_cps_brand_goods.id || 0;
                        return void wx.redirectTo({
                            url: "/packageH/cpsDetail/cpsDetail?id=" + n
                        });
                    }
                    var h = {
                        title: d.get_goods.has_one_share && d.get_goods.has_one_share.share_title ? d.get_goods.has_one_share.share_title : d.get_goods.title,
                        imgUrl: d.get_goods.has_one_share && d.get_goods.has_one_share.share_thumb ? d.get_goods.has_one_share.share_thumb : d.get_goods.thumb
                    };
                    if (t.setData({
                        prop_goods_info: a.data,
                        title: d.get_goods.title,
                        shareInfo: h
                    }), "[object Object]" === Object.prototype.toString.call(r) && wx.redirectTo({
                        url: "/packageF/consumption/goodsDetails/goodsDetails?goodsId=" + t.data.goods_id
                    }), console.log(d.get_goods), 154 === (null === (i = d.get_goods) || void 0 === i ? void 0 : i.plugin_id)) return void wx.redirectTo({
                        url: "/packageF/tourAround/tourAroundGoodsDetails/tourAroundGoodsDetails?goodsId=" + t.data.goods_id
                    });
                    if (157 === (null === (s = d.get_goods) || void 0 === s ? void 0 : s.plugin_id)) return void wx.redirectTo({
                        url: "/packageF/sachertorte/sachertorteGoods/sachertorteGoods?id=" + t.data.goods_id
                    });
                    d.plugin && d.plugin.customer_development && t.setData({
                        is_toker: !0
                    }), d.goods_type && t.setData({
                        goods_type: d.goods_type
                    }), "goods" == t.data.goods_type ? t.cGoods = t.selectComponent("#cGoods") : "supplierGoods" == t.data.goods_type ? t.supplierGoods = t.selectComponent("#supplierGoods") : "hotelGoods" == t.data.goods_type && (t.hotelGoods = t.selectComponent("#hotelGoods"));
                } else "该商家已过期,去看看其他的吧" == a.msg ? t.setData({
                    prop_goods_info: {}
                }) : wx.showModal({
                    title: "提示",
                    content: a.msg,
                    showCancel: !1,
                    success: function(t) {
                        t.confirm && wx.navigateBack({
                            fail: function() {
                                wx.reLaunch({
                                    url: "/packageG/index/index"
                                });
                            }
                        });
                    }
                });
                wx.hideLoading();
            },
            fail: function(t) {}
        });
    },
    firstlogin: function() {
        var t = !1;
        try {
            var o = wx.getStorageSync("yz_basic_info");
            if (o) "goods02" == o.home.item.ViewSet.goods.code && (this.setData({
                loginshow: !1
            }), t = !1); else wx.getStorageSync("wx_token") ? (this.setData({
                loginshow: !1
            }), t = !1) : (this.setData({
                loginshow: !0
            }), t = !0);
        } catch (t) {}
        return t;
    },
    gotologin: function() {
        a.seyzredirect(), wx.navigateTo({
            url: "/pages/login/login"
        });
    },
    goLiveBtn: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    getRetailGoods: function() {
        var t = this, o = a.getNetAddresss("plugin.new-retail.frontend.index.goodsDetail");
        a._postNetWork({
            showToastIn: !1,
            url: o,
            data: {
                goods_id: this.data.goods_id,
                is_retail_goods: this.options.md
            },
            success: function(o) {
                var a = o.data;
                if (1 == a.result) {
                    var e = a.data.goods;
                    t.setData({
                        prop_goods_info: e,
                        goods_type: "retailGood"
                    });
                } else "该商家已过期,去看看其他的吧" == a.msg ? t.setData({
                    prop_goods_info: {}
                }) : wx.showModal({
                    title: "提示",
                    content: a.msg,
                    showCancel: !1,
                    success: function(t) {
                        t.confirm && wx.navigateBack({
                            fail: function() {
                                wx.reLaunch({
                                    url: "/packageG/index/index"
                                });
                            }
                        });
                    }
                });
                wx.hideLoading();
            },
            fail: function(t) {}
        });
    }
});